package com.amit.hibernate;


import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Lab21Clent2 {

	public static void main(String[] args) {
		
		SessionFactory sessionfactory=CHibernateUtil.getfactory();
		Session session=sessionfactory.openSession();
		Transaction tx=session.beginTransaction();
		Customer cust=(Customer) session.load(Customer.class, 1);
		System.out.println(cust.getCid()+" "+cust.getCname()+" "+cust.getEmail()+" "+cust.getPhone());
		
		Set<Account> acs=cust.getAccounts();
		
		for(Account acc:acs)
		{
		System.out.println(acc.getAccno()+" "+acc.getAtype()+" "+acc.getBal());	
		}
		
		
		Account ac=(Account) session.load(Account.class, 2);
		System.out.println(ac.getAccno()+" "+ac.getAtype()+" "+ac.getBal());
		
		Set<Customer> ccs=ac.getCustomers();
		
		for(Customer cus:ccs)
		{
		System.out.println(cus.getCid()+" "+cus.getCname()+" "+cus.getEmail()+" "+cus.getPhone());	
		}
		
		
		
		
		tx.commit();
		session.close();
		
	
	}

}
